<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Customer Home Page</title>

<script language="JavaScript" type="text/javascript">
function getauction(auctionid)
{
  document.testform.auctionId.value = auctionid;
  document.testform.submit();
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery_tabs.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function() {$('#tabs_news').tabs({ fxFade: true, fxSpeed: 'fast' });});
</script>
</head>
<body>
<div class="main">
  <div class="header">
    <div class="resize">
      <div class="logo"><img src="images/logo.png" alt="picture" width="171" height="42" border="0" /></a></div>
      <div class="clr"></div>
    </div>
    <div class="clr"></div>
  </div>
  <div class="slider_resize">
    <div class="clr"></div>
  </div>
  <div class="FBG">
    <div class="clr"></div>
  </div>
  <div class="body">
    <div class="resize">
      <div class="left">
      
        		<%
  		/////////////////////////////////////////////////////////////////////
  		// PUT CUSTOMER'S DATA CODE HERE!!!!!                              //
  		/////////////////////////////////////////////////////////////////////
  		%>
      
        <h2><%=session.getValue("login")%>'s Data</h2>

<% 
        
        String username = ""+session.getValue("login");
  			java.sql.Connection conn=null;
			try 
			{
            	Class.forName((String)session.getValue("mysJDBCDriver")).newInstance();
    			java.util.Properties sysprops=System.getProperties();
    			sysprops.put("user",(String)session.getValue("mysUserID"));
    			sysprops.put("password",(String)session.getValue("mysPassword"));
        
				//connect to the database
            			conn=java.sql.DriverManager.getConnection((String)session.getValue("mysURL"),sysprops);
            			System.out.println("Connected successfully to database using JConnect");
            
            			java.sql.Statement stmt1=conn.createStatement();
        
					java.sql.ResultSet rs = stmt1.executeQuery("select * from Customer_Self_DATA where Customer_Self_DATA.UserName = '"+username+"'");
%>
      	  <form name="testform" method="get" action="AuctionInfo.jsp">
      	  <input type="hidden" name="auctionId"/>
 <%
      	  
      	  while(rs.next())
      	  {
%>			        <table id="CustomerData" width="550">
                    <tr>
                    	<td>First Name</td>
                   		<td><span style="font-size: 10pt"><%=rs.getString(1)%></span></td>
                    </tr>
                    <tr>
                        <td>Last Name</td>
						<td><span style="font-size: 10pt"><%=rs.getString(2)%></span></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                     	<td><span style="font-size: 10pt"><%=rs.getString(3)%></span></td>
                    </tr>
                    <tr> 
                        <td>City</td>
                        <td><span style="font-size: 10pt"><%=rs.getString(4)%></span></td>
                    </tr>
                    <tr>
                        <td>State</td>
                        <td><span style="font-size: 10pt"><%=rs.getString(5)%></span></td>
                    </tr>
                    <tr>
                        <td>Zipcode</td>
                        <td><span style="font-size: 10pt"><%=rs.getString(6)%></span></td>
                    </tr>
                    <tr>
                        <td>Phone #</td>
                        <td><span style="font-size: 10pt"><%=rs.getString(7)%></span></td>
                    </tr>
                    <tr>
                        <td>Email</td>
                        <td><span style="font-size: 10pt"><%=rs.getString(8)%></span></td>
                    </tr>
                    <tr>
                        <td>Credit Card</td>
                        <td><span style="font-size: 10pt"><%=rs.getString(9)%></span></td>
                    </tr>
<%     		
        	}
  			} catch(Exception e)
			{
				e.printStackTrace();
				out.print(e.toString());
			}
			finally{
			
				try{conn.close();}catch(Exception ee){};
			}

  %>
  			</form>
  		</table>        
        
  		<%
  		/////////////////////////////////////////////////////////////////////
  		// PUT THE VIEW PURCHASE HISTORY CODE HERE!!!!!                    //
  		/////////////////////////////////////////////////////////////////////
  		%>
        
        
        <h2><%=session.getValue("login")%>'s Purchase History</h2>
        <table id="PurchaseHistory" width="500">
                    <tr>
                      <td>
                          Item</td>
                        <td>
                            Auction Number</td>
                        <td>
                            Purchase Date</td>
                    </tr>   
<% 
        
  			int count = 0;
			try 
			{
            	Class.forName((String)session.getValue("mysJDBCDriver")).newInstance();
    			java.util.Properties sysprops=System.getProperties();
    			sysprops.put("user",(String)session.getValue("mysUserID"));
    			sysprops.put("password",(String)session.getValue("mysPassword"));
        
				//connect to the database
            			conn=java.sql.DriverManager.getConnection((String)session.getValue("mysURL"),sysprops);
            			System.out.println("Connected successfully to database using JConnect");
            
            			java.sql.Statement stmt1=conn.createStatement();
        
					java.sql.ResultSet rs = stmt1.executeQuery("select * from Purchase_History where Purchase_History.UserName = '"+username+"'");
      	  
      	  int auctionID;
%>
      	  <form name="testform" method="get" action="AuctionInfo.jsp">
      	  <input type="hidden" name="auctionId"/>
 <%
      	  
      	  while(rs.next())
      	  {
      	  	auctionID = rs.getInt(3);
      		 count++;
%>			
                    <tr>
                      <td>
                          <span style="font-size: 10pt"><%=rs.getString(2)%></span></td>
                      <td>
                          <span style="font-size: 10pt"><%=rs.getString(3)%></span></td>
                     <td>
                         <span style="font-size: 10pt"><%=rs.getString(4)%></span></td>
                    </tr>
<%     		
        	}
  			} catch(Exception e)
			{
				e.printStackTrace();
				out.print(e.toString());
			}
			finally{
			
				try{conn.close();}catch(Exception ee){};
			}

  %>
  			</form>
  		</table>
  		
  		<%
  		if(count < 1) //No purchase history
  		{
  			%>
  			<p>You have no purchases. Start buying some snazzy items today!</p>
  			<%
  		}
  		
  		//////////////////////////////////////////////
  		// PUT THE RECOMMENDED CODE Below HERE!!!!! //
  		//////////////////////////////////////////////
  		%>
  		
  		<h2><%=session.getValue("login")%>'s Recommended Items</h2>
  		        <table id="PurchaseHistory" width="500">
                    <tr>
                        <td>Item Name</td>
                        <td>Item Type</td>
                        <td>Auction ID</td>
                    </tr>  
  		<% 
        
        	username = ""+session.getValue("login");
  			conn=null;
			try 
			{
            	Class.forName((String)session.getValue("mysJDBCDriver")).newInstance();
    			java.util.Properties sysprops=System.getProperties();
    			sysprops.put("user",(String)session.getValue("mysUserID"));
    			sysprops.put("password",(String)session.getValue("mysPassword"));
        
				//connect to the database
            			conn=java.sql.DriverManager.getConnection((String)session.getValue("mysURL"),sysprops);
            			System.out.println("Connected successfully to database using JConnect");
            
            			java.sql.Statement stmt1=conn.createStatement();
        
					java.sql.ResultSet rs = stmt1.executeQuery("select * from Customer_PersonalList where Customer_PersonalList.UserName = '"+username+"'");
%>
      	  <form name="testform" method="get" action="AuctionInfo.jsp">
      	  <input type="hidden" name="auctionId"/>
 <%
      	  count = 0;
      	  while(rs.next())
      	  {
%>			
                    <tr>
                      <td>
                          <span style="font-size: 10pt"><%=rs.getString(2)%></span></td><td>
                          <span style="font-size: 10pt"><%=rs.getString(3)%></span></td><td>
                          <span style="font-size: 10pt"><%=rs.getString(4)%></span></td>
                          
                    </tr>
<%     		
        	}
  			} catch(Exception e)
			{
				e.printStackTrace();
				out.print(e.toString());
			}
			finally{
			
				try{conn.close();}catch(Exception ee){};
			}

  %>
  			</form>
  		</table>  
  		  		<%
  		if(count < 1) //No purchase history
  		{
  			%>
  			<p>You have no recommended items. You need to start buy some items or other users need to make more auctions.</p>
  			<%
  		}
  		  		%>
      </div>
      <div class="right">
        <h2>Create an Auction</h2>
		<form name="myForm" action="login.jsp" method="post">
		<input id="NewAuctionButton" type="button" value="Post New Auction" onclick="window.open('NewAuction.jsp','_self')"/>
		</form>
        </br>
        <h2>Search Auctions</h2>
        <form action="SearchdAuction.jsp" method="post">

			<table>
				<tr>
					<td>Item Name: </td>
					<td><input type="text" name="itemName"/></td>
				</tr>
				<tr>
					<td>Item Year: </td>
					<td><input type="text" name="itemYear"/></td>
				</tr>
				<tr>
					<td>Item Type</td>
					<td>
						<select name="itemType">
							<option value=""></option>
							<option value="Car">Car</option>
							<option value="DVD">DVD</option>
							<option value="Electronics">Electronics</option>
							<option value="Clothing & Jewelry">Clothing & Jewelry</option>
							<option value="Sporting Goods">Sporting Goods</option>
							<option value="Collectables">Collectables</option>
							<option value="Home & Garden">Home & Garden</option>						
						</select>
					</td>
				</tr>
				<tr>
					<td>Open Auctions Only: </td>
					<td><input type="checkbox" checked="yes" name="openAuctionsOnly"/></td>
				</tr>
			</table>
			<br/>
			<button name="searchButton" >Search</button>
		</form>
		</br>
		<h2>Logout</h2>
		<input id="Button1" type="button" value="Logout" onclick="window.open('index.htm','_self');" />
        
      </div>
      <div class="clr"></div>
    </div>
  </div>
  <div class="footer">
    <div class="resize" style="background:#141414;">
				<p class="leftt">
					Created by: Andrew Gratta, Sarah Jordan, and Kevin O'Flaherty<br /></p>
      <p class="rightt"><span class="leftt">Copyright. All Rights Reserved</span></p>
      <p class="rightt">Developed for CSE305 at Stony Brook University</p>
      <div class="clr"></div>
    </div>
  </div>
</div>
</body>
</html>
